﻿Imports Phila
Imports Phila.Sql
Imports Phila.CommonClasses

Public Class EditHotelCategory
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If Session.Item("UserID") Is Nothing Then
                'Response.Redirect("Login.aspx")
            End If
            If Not IsPostBack = True Then
                If Not Request.QueryString("Id") Is Nothing Then
                    fillData(Request.QueryString("Id"))
                End If
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Protected Sub fillData(ByVal Id As Integer)
        Dim txt As Array
        txt = RetriveData("SELECT [Id],[Name],[Caption], [IsActive] FROM [ptn_HotelCategory] where Id=" & Id, 3)
        txtName.Text = Server.HtmlDecode(txt(1))
        txtCaption.Text = Server.HtmlDecode(txt(2))
        chkActive.Checked = txt(3)
    End Sub

    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            Dim strActive As String
            If chkActive.Checked = True Then
                strActive = 1
            Else
                strActive = 0
            End If
            If Request.QueryString("Id") Is Nothing Then
                Dim arr As Array
                arr = RetriveData("Select Id from ptn_HotelCategory where Name='" & Server.HtmlEncode(Trim(txtName.Text.Replace("'", "&#039;"))) & "'", 0)
                If arr(0) Is Nothing Then
                    Insert_Update_Delete_Record("Insert into ptn_HotelCategory (Name, Caption, IsActive) values('" & Server.HtmlEncode(txtName.Text.Replace("'", "&#039;")) & "','" & Server.HtmlEncode(Trim(txtCaption.Text.Replace("'", "&#039;"))) & "'," & strActive & ")")
                    Response.Redirect("ViewRoomCategory.aspx")
                Else
                    lblMsg.Text = "Hotel Category already exist."
                End If
            Else
                Insert_Update_Delete_Record("Update ptn_HotelCategory set Name='" & Server.HtmlEncode(txtName.Text.Replace("'", "&#039;")) & "', Caption='" & Server.HtmlEncode(Trim(txtCaption.Text.Replace("'", "&#039;"))) & "',IsActive=" & strActive & " where Id=" & Request.QueryString("Id"))
                Response.Redirect("ViewHotelCategory.aspx")
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Response.Redirect("ViewHotelCategory.aspx")
    End Sub
End Class